#pragma once

#include <iostream>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>

class InerAddr
{
public:
    InerAddr(struct sockaddr_in &addr) : _addr(addr)
    {
        _port = ntohs(addr.sin_port);           // 从网络中拿到的
        _ip = inet_ntoa(addr.sin_addr); // 4字节网络风格 -> 点分十进制的字符串风格的IP
    }

    std::string Ip() const { return _ip; }
    uint16_t Port() const { return _port; }
    const struct sockaddr_in &NetAddr() { return _addr; }

    bool operator==(const InerAddr& addr) const
    {
        return addr._ip == _ip && addr._port == _port;
    }
    std::string StringAddr() const
    {
        return _ip + ":" + std::to_string(_port);
    }
    ~InerAddr()
    {

    }
private:
    struct sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
};
